package com.wxd.woff.table;

import com.wxd.woff.AbstractOTFDataStream;
import com.wxd.woff.AbstractWoffTable;
import com.wxd.woff.ByteBufferOTFDataStream;
import com.wxd.woff.WoffFont;

import java.io.IOException;

/**
 * hhea table Created with IntelliJ IDEA.
 *
 * @author: wangxindong
 * @date: 2018/9/1-23:01
 */
public class HorizontalHeaderTable extends AbstractWoffTable {

	public static final String TAG = "hhea";

	private int majorVersion;
	private int minorVersion;
	private short ascender;
	private short descender;
	private short lineGap;
	private int advanceWidthMax;
	private short minLeftSideBearing;
	private short minRightSideBearing;
	private short xMaxExtent;
	private short caretSlopeRise;
	private short caretSlopeRun;
	private short reserved1;
	private short reserved2;
	private short reserved3;
	private short reserved4;
	private short caretOffset;
	private short metricDataFormat;
	private int numberOfHMetrics;

	public HorizontalHeaderTable(WoffFont woffFont) {
		super(woffFont);
	}

	@Override
	public void read(WoffFont woffFont, AbstractOTFDataStream stream) throws IOException {
		stream.seek(offset);
		byte[] fontData = stream.read(compLength);
		byte[] inflateFont = inflateFontData(fontData);
		AbstractOTFDataStream data = new ByteBufferOTFDataStream(inflateFont);
		majorVersion = data.readUnsignedShort();
		minorVersion = data.readUnsignedShort();
		ascender = data.readSignedShort();
		descender = data.readSignedShort();
		lineGap = data.readSignedShort();
		advanceWidthMax = data.readUnsignedShort();
		minLeftSideBearing = data.readSignedShort();
		minRightSideBearing = data.readSignedShort();
		xMaxExtent = data.readSignedShort();
		caretSlopeRise = data.readSignedShort();
		caretSlopeRun = data.readSignedShort();
		caretOffset = data.readSignedShort();
		reserved1 = data.readSignedShort();
		reserved2 = data.readSignedShort();
		reserved3 = data.readSignedShort();
		reserved4 = data.readSignedShort();
		metricDataFormat = data.readSignedShort();
		numberOfHMetrics = data.readUnsignedShort();
	}

	public int getMajorVersion() {
		return majorVersion;
	}

	public void setMajorVersion(int majorVersion) {
		this.majorVersion = majorVersion;
	}

	public int getMinorVersion() {
		return minorVersion;
	}

	public void setMinorVersion(int minorVersion) {
		this.minorVersion = minorVersion;
	}

	public short getAscender() {
		return ascender;
	}

	public void setAscender(short ascender) {
		this.ascender = ascender;
	}

	public short getDescender() {
		return descender;
	}

	public void setDescender(short descender) {
		this.descender = descender;
	}

	public short getLineGap() {
		return lineGap;
	}

	public void setLineGap(short lineGap) {
		this.lineGap = lineGap;
	}

	public int getAdvanceWidthMax() {
		return advanceWidthMax;
	}

	public void setAdvanceWidthMax(int advanceWidthMax) {
		this.advanceWidthMax = advanceWidthMax;
	}

	public short getMinLeftSideBearing() {
		return minLeftSideBearing;
	}

	public void setMinLeftSideBearing(short minLeftSideBearing) {
		this.minLeftSideBearing = minLeftSideBearing;
	}

	public short getMinRightSideBearing() {
		return minRightSideBearing;
	}

	public void setMinRightSideBearing(short minRightSideBearing) {
		this.minRightSideBearing = minRightSideBearing;
	}

	public short getxMaxExtent() {
		return xMaxExtent;
	}

	public void setxMaxExtent(short xMaxExtent) {
		this.xMaxExtent = xMaxExtent;
	}

	public short getCaretSlopeRise() {
		return caretSlopeRise;
	}

	public void setCaretSlopeRise(short caretSlopeRise) {
		this.caretSlopeRise = caretSlopeRise;
	}

	public short getCaretSlopeRun() {
		return caretSlopeRun;
	}

	public void setCaretSlopeRun(short caretSlopeRun) {
		this.caretSlopeRun = caretSlopeRun;
	}

	public short getReserved1() {
		return reserved1;
	}

	public void setReserved1(short reserved1) {
		this.reserved1 = reserved1;
	}

	public short getReserved2() {
		return reserved2;
	}

	public void setReserved2(short reserved2) {
		this.reserved2 = reserved2;
	}

	public short getReserved3() {
		return reserved3;
	}

	public void setReserved3(short reserved3) {
		this.reserved3 = reserved3;
	}

	public short getReserved4() {
		return reserved4;
	}

	public void setReserved4(short reserved4) {
		this.reserved4 = reserved4;
	}

	public short getCaretOffset() {
		return caretOffset;
	}

	public void setCaretOffset(short caretOffset) {
		this.caretOffset = caretOffset;
	}

	public short getMetricDataFormat() {
		return metricDataFormat;
	}

	public void setMetricDataFormat(short metricDataFormat) {
		this.metricDataFormat = metricDataFormat;
	}

	public int getNumberOfHMetrics() {
		return numberOfHMetrics;
	}

	public void setNumberOfHMetrics(int numberOfHMetrics) {
		this.numberOfHMetrics = numberOfHMetrics;
	}

	@Override
	public String toString() {
		return "AbstractWoffTable{" + "tag='" + tag + '\'' + ", offset=" + offset + ", compLength=" + compLength
				+ ", origLength=" + origLength + ", origChecksum=" + origChecksum + ", majorVersion=" + majorVersion
				+ ", minorVersion=" + minorVersion + ", ascender=" + ascender + ", descender=" + descender
				+ ", lineGap=" + lineGap + ", advanceWidthMax=" + advanceWidthMax + ", minLeftSideBearing="
				+ minLeftSideBearing + ", minRightSideBearing=" + minRightSideBearing + ", xMaxExtent=" + xMaxExtent
				+ ", caretSlopeRise=" + caretSlopeRise + ", caretSlopeRun=" + caretSlopeRun + ", reserved1=" + reserved1
				+ ", reserved2=" + reserved2 + ", reserved3=" + reserved3 + ", reserved4=" + reserved4
				+ ", caretOffset=" + caretOffset + ", metricDataFormat=" + metricDataFormat + ", numberOfHMetrics="
				+ numberOfHMetrics + "]";
	}

}
